package com.sc.service.impl.csm;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.Character;
import com.sc.dto.CharacterDTO;
import com.sc.mapper.csm.CharacterMapper;
import com.sc.service.csm.ICharacterService;
import org.springframework.stereotype.Service;

@Service
public class CharacterServiceImpl extends ServiceImpl<CharacterMapper, Character> implements ICharacterService {

    @Override
    public Page<Character> pageQuery(CharacterDTO characterDTO) {
        QueryWrapper<Character> wrapper = Wrappers.emptyWrapper();
        String characterName = characterDTO.getCharacterName();

        if (characterName != null && !characterName.isEmpty()) {
            wrapper = new QueryWrapper<>();
            wrapper.like("character_name", characterName);
        }

        Page<Character> page = new Page<>(characterDTO.getPageNum(), characterDTO.getPageSize());
        Page<Character> characterPage = page(page, wrapper);
        return characterPage;
    }
}
